home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)cpit_event.c V1.7 3/15/95";
- #endif
-
- /*------------------------------------------------------------------
- | file name -- cpit_event.c
- |
- | functions Description
- | --------- -----------
- | InitSimpleEvents Sets up service routines for simple event handling.
- | HandleEvents Gathers and processes user inputs
- |
- | handle_pick_event Service Function for pick events.
- | handle_window_event Service Function for window events.
- | handle_quit_window Quits the application or close the window.
- | check_hot_spots Checks and handles commands contained in picked
- | objects' names.
- |
- | ParseCommand Analyzes the command contained in the chosen
- | object's name.
- |
- |-----------------------------------------------------------------*/
-
- /* This program can be linked to run:
- |
- | With 100% CPU usage (which shows updates in a tight loop)
- | comment #define DV_USE_TIMER
- | With Time-Outs (which show update based on a timer.
- | uncomment #define DV_USE_TIMER
- */
- #define DV_USE_TIMER
-
- #include "std.h"
- #include "dvstd.h"
- #include "dvtools.h"
- #include "dvGR.h"
- #include "VOstd.h"
- #include "Tfundecl.h"
- #include "dvinteract.h"
- #include "VOfundecl.h"
- #include "VUerfundecl.h"
- #include "VGfundecl.h"
- #include "cpit_vars.h"
- #include "cpit_fundecl.h"
-
-
-
- /***************** Begin Function Declarations *************/
- LOCAL void handle_pick_event V_P_((OBJECT location));
- LOCAL void handle_quit_window V_P_((void));
- /***************** End Function Declarations *************/
-
- /*-----------------------------------------------------------------
- |
- | InitSimpleEvents()
- | Performs the initialization needed for window events.
- |
- */
- void InitSimpleEvents
- V_P_ ((void))
- {
-
- /* Setup the window events */
- (VOID) VOscWinEventMask ((ULONG) (V_KEYPRESS | V_BUTTONPRESS |
- V_KEYRELEASE | V_BUTTONRELEASE |
- V_RESIZE | V_EXPOSE |
- V_MOTIONNOTIFY |
- V_WINDOW_QUIT),
- (ULONG) V_END_OF_LIST);
- }
-
- /*-----------------------------------------------------------------
- |
- | HandleEvents
- | Gathers and processes user input. Events are first processed
- | by the event handler then checked on a case by case basis.
- */
- void HandleEvents
- V_P_ ((void))
- {
- OBJECT loc_event;
-
- /* See if there is an event to handle, only user input events
- | matching those set in VOscWinEventMask will be returned.
- |
- | NOTE: VOloWinEventPoll will get the next event and then dispatch
- | non-DataViews events. Our posted AppTimeOut event to handle
- | dynamics, will be called as needeb by VOloWinEventPoll, which
- | calls XtAppNextEvent and XtDispatchEvent.
- */
-
- #ifdef DV_USE_TIMER
-
- loc_event = VOloWinEventPoll (V_WAIT);
-
- #else /* Not DV_USE_TIMER */
-
- /* Update the Display */
- HandleDynamics();
-
- /* Get the Event */
- loc_event = VOloWinEventPoll (V_NO_WAIT);
-
- #endif /* DV_USE_TIMER */
-
-
- /* If there is an event, handle it */
- if (loc_event)
- {
- ActiveScreen = VOloScreen (loc_event);
- (VOID) TscSetCurrentScreen (ActiveScreen);
-
- /* Let the event handler update input objects and...
- | PICK events: HandlPickEvent() will be called
- | WINDOW events: handle_window_event() will be called
- */
- (VOID) VUerHandleLocEvent (loc_event);
-
- /* Now Look for Events */
- switch (VOloType (loc_event))
- {
- case V_RESIZE:
- (VOID) TscReset (ActiveScreen);
- break;
- case V_EXPOSE:
- (VOID) TscRedraw (ActiveScreen, (RECTANGLE *) NULL);
- break;
- case V_WINDOW_QUIT:
- handle_quit_window ();
- break;
- case V_BUTTONPRESS:
- handle_pick_event (loc_event);
- break;
- }
- }
- }
-
- /*-----------------------------------------------------------------
- |
- | handle_pick_event
- |
- | Checks to see if we've selected a named object. If we have
- | it parses the command embedded in the name.
- |
- | Only the first letter of the name is used for the command.
- | The commands have the following meanings:
- |
- |
- | NOTE: The <varname> field will be used at a later date
- | to control the dynamics in certain objects. Currently
- | you will find no routines that make use of this field.
- |
- | Q********* - Quits the application
- |
- | G:<viewname> - Goto viewname
- | N:<varname> - Starts a linked list of NEXT views.
- | P:<varname> - Display the PREVIOUS view.
- |
- | O:<viewname> - OVERLAYS the named view.
- | D:<viewname> - DELETES the overlayed named view.
- |
- */
- /* ARGSUSED */
- LOCAL void
- handle_pick_event (location)
- OBJECT location;
- {
- CHAR *obj_name, *cmd;
- DRAWPORT dp;
- OBJECT obj, dr;
-
- /* Find the selected object */
- dp = TloGetSelectedDrawport (location);
- obj = TloGetSelectedObject (location);
-
- if (obj)
- {
- /* Get the object's name */
- dr = TviGetDrawing (TdpGetView (dp));
- obj_name = TdrGetObjectName (dr, obj);
-
- /* Handle the command associated with the object's name */
- if (obj_name)
- {
- cmd = obj_name;
-
- /* Process the current command */
- switch ((INT) cmd[0])
- {
- /* OVERLAY display (O) */
- case OVERLAY_COMMAND:
- OverlayDisplay (&cmd[2]); /* found in cpit_dsp.c */
- break;
-
- /* RESET Display (G) */
- case GOTO_COMMAND:
- SwitchDisplay (RESET_DISPLAY, &cmd[2]); /* found in cpit_dsp.c */
- break;
-
- /* NEXT Display (G) */
- case NEXT_COMMAND:
- SwitchDisplay (NEXT_DISPLAY, &cmd[2]); /* found in cpit_dsp.c */
- break;
-
- /* PREVIOUS display (P) */
- case PREVIOUS_COMMAND:
- SwitchDisplay (PREV_DISPLAY, (CHAR *) NULL); /* found in cpit_dsp.c */
- break;
-
- /* DELETE command (D) */
- case DELETE_COMMAND:
- RemoveDisplay (&cmd[2]); /* found in cpit_dsp.c */
- break;
-
- /* QUIT the application */
- case QUIT_COMMAND:
- handle_quit_window ();
- break;
-
- default:
- break;
- }
- }
- }
- }
-
- /*-----------------------------------------------------------------
- |
- | handle_quit_window
- | Sets the quit flag to stop the program.
- */
- LOCAL void handle_quit_window
- V_P_ ((void))
- {
- ApplicationState = (DV_BOOL) NOT_RUNNING;
- }
-